package patrol.mobile.com.mobilepatrol.activity.security.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;

import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.security.emergency.EmergencySaveCheck2Activity;
import patrol.mobile.com.mobilepatrol.activity.security.emergency.EmergencyZG2Activity;
import patrol.mobile.com.mobilepatrol.bean.SaveCheckLeaderCopyListBean;
import patrol.mobile.com.mobilepatrol.utils.ToastUtils;

/**
 * Created by K on 2018/9/11.
 * des:
 */
public class EmergencySaveZG1ListAdapter extends BaseQuickAdapter<SaveCheckLeaderCopyListBean> {
    public EmergencySaveZG1ListAdapter(Context context) {
        super(context);
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.item_emergency_save_zg1_list;
    }

    @Override
    protected void convert(BaseViewHolder holder, final SaveCheckLeaderCopyListBean item) {
        holder.setText(R.id.tv_num, (holder.getLayoutPosition() + 1) + "");
        holder.setText(R.id.tv_orgName, item.getOrgName());
        holder.setText(R.id.tv_problemName, item.getProblemName());
        holder.setText(R.id.tv_rectifyBy, item.getRectifyBy());
        if (item.getProblemLevel().equals("0")) {
            holder.setText(R.id.tv_problemLevel, "无隐患");
        } else if (item.getProblemLevel().equals("1")) {
            holder.setText(R.id.tv_problemLevel, "一般隐患");
        } else {
            holder.setText(R.id.tv_problemLevel, "重大隐患");
        }
        holder.setText(R.id.tv_yesRectify, item.getYesRectify().equals("0") ? "未整改" : "已整改");
        holder.setText(R.id.tv_checkDate, item.getCheckDate());
        holder.setText(R.id.tv_auditName, TextUtils.isEmpty(item.getAuditName()) ? "  " : item.getAuditName());


        holder.getView(R.id.rl_root).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, EmergencySaveCheck2Activity.class);
                intent.putExtra("id", item.getId());
                mContext.startActivity(intent);
            }
        });

        holder.setOnClickListener(R.id.tv_zg, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (item.getYesRectify().equals("0")) {
                    Intent intent = new Intent(mContext, EmergencyZG2Activity.class);
                    intent.putExtra("id", item.getId());
                    mContext.startActivity(intent);
                } else {
                    ToastUtils.showToast("当前已整改无需修改");
                }
            }
        });

        holder.setOnClickListener(R.id.tv_fh, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (item.getYesRectify().equals("1")) {
                    Intent intent = new Intent(mContext, EmergencyZG2Activity.class);
                    intent.putExtra("id", item.getId());
                    intent.putExtra("auditFlag", "2");
                    intent.putExtra("auditName", "已复合");
                    mContext.startActivity(intent);
                } else {
                    ToastUtils.showToast("请先整改");
                }
            }
        });


    }
}
